﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microhard.Core.DBUtility;
using Microhard.Protal.Validators;

namespace Microhard.Protal.Models
{
    [FluentValidation.Attributes.Validator(typeof(CategoryModelValidator))]
    public class CategoryModel : BasePermissionModel
    {
        [Microhard.Core.DBUtility.ModelPKID]
        public Guid CategoryID { set; get; }
        /// <summary>
        /// 名称
        /// </summary>
        public string Name { set; get; }
        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreationTime { set; get; }
        /// <summary>
        /// 父分类ID
        /// </summary>
        public Guid? ParentCategoryID { set; get; }
        public string ParentCategoryName { set; get; }
        /// <summary>
        /// 所有子节点
        /// </summary>
        public List<CategoryModel> Subs { set; get; }
        /// <summary>
        /// 类别所属产品
        /// </summary>
        public List<ProductModel> Products { set; get; }
        public string NamesOfProduct
        {
            get
            {
                StringBuilder result = new StringBuilder();
                if (this.Products != null)
                {
                    if (Products.Count > 0)
                    {
                        Products.ForEach(item =>
                        {
                            result.Append(item.Name + ",");
                        });
                    }
                }
                return result.ToString();
            }
        }
        public Guid CompanyID { set; get; }


        public string Description { set; get; }
        public string DescriptionContent { set; get; }
    }
}
